package Studing;

import java.util.*;

/**
 * @ClassName SetTest
 * @Description: TODO
 * @Author hl
 * @Date 2020/8/4
 * @Version V1.0
 **/
public class SetTest {
    public static void main(String[] args) {
         int arr[]={7,9,11,16,19,20,27,40,48,55,67,69,71,83,89,97};
         binarySearch(arr,89);
    }
    public static int binarySearch(int[] nums, int key) {
        int l = 0, h = nums.length - 1;
        int count=0;
        while (l <= h) {
            System.out.println(++count);
            int m = l + (h - l) / 2;
            if (nums[m] == key) {
                return m;
            } else if (nums[m] > key) {
                h = m - 1;
            } else {
                l = m + 1;
            }
        }
        return -1;
    }
}
